import api, { getAction, deleteAction, putAction, postAction, httpAction } from '@/api/manage'
import Vue from 'vue'
import { UI_CACHE_DB_DICT_DATA } from '@/store/mutation-types'
import { axios } from '@/utils/request'

//数据采集中心-数据源参数定义
const editCollectSourceParamsDefine = (params) => putAction('/dcloud-platform/api/collectSource/ParamsDefine/v1/edit', params)
const addCollectSourceParamsDefine = (params) => postAction('/dcloud-platform/api/collectSource/ParamsDefine/v1/add', params)
const deleteCollectSourceParamsDefine = (params) => deleteAction('/dcloud-platform/api/collectSource/ParamsDefine/v1/delete', params)

//数据采集中心-任务相关
const editCollectTask = (params) => putAction('/dcloud-platform/api/task/v1/edit', params)

const listCollectTask = (params) => getAction('/dcloud-platform/api/task/v1/list/nopage', params)
const addCollectTask = (params) => postAction('/dcloud-platform/api/task/v1/add', params)


//数据流程编排相关
const listCompTree = () => getAction('/dcloud-platform/api/aipcomp/v1/tree')

//根据任务id获取流程信息，如果流程不存在，自动创建一个流程
const getFlowByTaskId = (params) => postAction('/dcloud-platform/api/aipflow/v1/getFlowByTaskId',params)

//根据任务id获取流程信息，如果流程不存在，自动创建一个流程
const updateFlowById = (params) => postAction('/dcloud-platform/api/aipflow/v1/updateById',params)

//流程节点配置参数保存
const saveNode = (params) => postAction('/dcloud-platform/api/aipflow/v1/node/save',params)
const getNodeInfoByNodeId = (params) => postAction('/dcloud-platform/api/aipflow/v1/node/info',params)

const genNodeParam = (params) => postAction('/dcloud-platform/api/aipflow/v1/node/gen/param',params)

const saveNodeFieldNode = (params) => postAction('/dcloud-platform/api/aipflow/v1/node/fieldMap/save',params)

//数据源相关
const listCollectSource = (params) => postAction('/dcloud-platform/api/collectSource/v1/list', params)
//根据数据源id查询数据源信息
const getInfoCollectSourceById = (params) => getAction('/dcloud-platform/api/collectSource//v1/info/byid', params)

//数据源接口
// const testSourceConn = (params)=>postAction("/dcloud-platform/api/collectSource/v1/testConn",params); //测试数据源是否可以连接

function testSourceConn(parameter) {
  return axios({
    url: '/dcloud-platform/api/collectSource/v1/testConn',
    method: 'post',
    params: parameter
  })
}

function jxSelect(parameter) {
  return axios({
    url: '/dcloud-platform/api/collectTaskSql/v1/jxSelect',
    method: 'post',
    params: parameter
  })
}

function fieldMap(parameter) {
  return axios({
    url: '/dcloud-platform/api/collectTaskSql/v1/fieldMap',
    method: 'post',
    params: parameter
  })
}

const updateBatchField = (params) => postAction('/dcloud-platform/api/collectTaskSql/v1/fieldMap/batchupdate ', params)

export {
  editCollectSourceParamsDefine,
  addCollectSourceParamsDefine,
  deleteCollectSourceParamsDefine,
  editCollectTask,
  addCollectTask,
  listCollectTask,
  testSourceConn,
  jxSelect,
  fieldMap,
  updateBatchField,
  // 流程相关
  listCompTree,
  getFlowByTaskId,
  updateFlowById,
  saveNode,
  getNodeInfoByNodeId,
  genNodeParam,
  saveNodeFieldNode,
  listCollectSource,
  getInfoCollectSourceById
}



